package com.cloudptt.api.product.func.media.device;

import android.content.Intent;
import android.content.IntentFilter;
import android.view.KeyEvent;

import com.cloudptt.api.comm.Const;
import com.cloudptt.api.product.func.media.EventListener;
import com.cloudptt.api.product.log.Log;

public class PDC680 implements IDeviceKey {
	public final static String THIS_FILE = "PDC680";
	private static final String BRAND = "Hytera";
	private static final String DEVICE = "PDC680";
	private static final String MODEL = "PDC680";

	private IntentFilter mFilter;
	private final static String ACTION_PTT = "com.cloudptt.wp.ptt";

	public PDC680(){
	}
	
	public static boolean isThisDev(String brand,String device,String model){
		if(brand == null
				|| device == null
				|| model == null){
			return false;
		}
		else if(BRAND.equals(brand)
				&& DEVICE.equals(device)
				&& MODEL.equals(model)){
			return true;
		}
		return false;
	}

	@Override
	public IntentFilter getBstIntentFilter() {
		mFilter = new IntentFilter();
		mFilter.addAction(ACTION_PTT);/**蓝牙指环PTT**/
		
		return mFilter;
	}
	
	@Override
	public void procBst(Intent intent, EventListener listener) {
		String action = intent.getAction();
		Log.d(THIS_FILE, " procBst action = " + action);
		Log.d(THIS_FILE, " procBst intent = " + intent);
		if(action.equals(ACTION_PTT)){
			int actionKey = intent.getIntExtra("action", -1);
			int keycode = intent.getIntExtra("keycode", -1);
			Log.d(THIS_FILE, " procBst actionKey = " + actionKey + " keycode = " + keycode);
//这里可以对按键做你想要的处理
			if(1001 == keycode) {
				if (actionKey == KeyEvent.ACTION_DOWN) {
					if (listener != null) {
						listener.onPtt(Const.MSG_TALK_ON, false, true);
					}
				} else if (actionKey == KeyEvent.ACTION_UP) {
					if (listener != null) {
						listener.onPtt(Const.MSG_TALK_OFF, false, true);
					}
				}
			}
		}
	}
}
